﻿
//删除数据需要同步删除相同的DescriptionOfSuppliesServices的数据.
function removeData(grid, hasDss) {
    var store = store = grid.getStore();
    var items = [];

    if (hasDss) {
        var editor = grid.getColumns()[0].getEditor(),
            r = editor.getStore().findRecord('code', e.data.DescriptionOfSuppliesServices);

        editor.getStore().remove(r);
    }

    if (store.data.items.length > 0) {
        for (var x = 0; x < store.data.items.length; x++) {
            var item = store.data.items[x];
            if (item.get('DescriptionOfSuppliesServices') == e.data.DescriptionOfSuppliesServices) {
                items[item.get('id')] = item;
            }
        }
        for (var key in items) {
            store.remove(items[key]);
        }
    }
}

removeData(ref.datagrid3, false);
removeData(ref.datagrid4);
removeData(ref.datagrid6);
removeData(ref.horizonGrid);


//获取当前grid所有的PA,并且拼接成where 语句
var paSql = [];

Ext.each(grid.store.data.items, function (rr) {
    paSql.push(" JSON_EXTRACT(t1.name,'$.en') = '" + rr.get('ProjectActivity') + "'");
});

Ext.PAIRest.request({
    ns: PAI.application.url,
    url: 'last/dictItemObj/customQuery',
    method: "POST",
    async: false,
    data: {
        "fields": [
            {
                "exp": "$." + PAI.Global.getLanguage(),
                "name": "description",
                "type": "json"
            }
        ],
        filter: "t1.pId='a65986df-3037-434f-8825-5db6ebd6fded' and (" + paSql.join(' or ') + ")"
    },
    success: function (result) {
        if (result.responseCode == '100') {
            var ukApprovers = [];

            Ext.each(result.data, function (rec) {
                ukApprovers.push(rec.description);
            });

            ref.ukFinanceApprover.setValue(ukApprovers.join(','));
        } else {
            ref.ukFinanceApprover.setValue('');
        }
    }
});